$(document).ready(function(){
	
});

function selProj(el)
{
	//alert(el.id);
	$.ajax({
	url: "project_leader_page.php",
	type: "POST",
	data: "projname="+el.id,
	success: function(data){
		name=data;
		$.ajax({
		url: "project_leader_page.php",
		type: "POST",
		data: "getModules="+el.id,
		success: function(modules){
			$.ajax({
			url: "project_leader_page.php",
			type: "POST",
			data: "selectProject="+el.id,
			success: function(html){
				$("#tasks").text(name);
				$("#tablediv").html(html);
				$("#projectid").val(el.id)
				$("#modulesDiv").html(modules)
		}
		});
			}
			});		
	}
	});
}

function centerPopup(popupName){  

//request data for centering  
var windowWidth = document.documentElement.clientWidth;  
var windowHeight = document.documentElement.clientHeight;  
var popupHeight = $("#"+popupName).height();  
var popupWidth = $("#"+popupName).width();  
//centering  
$("#"+popupName).css({  
"position": "absolute",  
"top": windowHeight/2-popupHeight/2,  
"left": windowWidth/2-popupWidth/2  
});  
//only need force for IE6  
  
$("#background").css({  
"height": windowHeight  
});  
  
}  

function openPopup(popupName)
{
popupStatus = 0;  

if(popupStatus==0)
	{  
$("#background").css({"opacity": "0.6"});  
$("#background").fadeIn("slow");  
$("#"+popupName).fadeIn("slow");  
popupStatus = 1;  

centerPopup(popupName);

}
}

function closePopup(popupName)
{  
//disables popup only if it is enabled  
if(popupStatus==1){  
$("#background").fadeOut("slow");  
$("#"+popupName).fadeOut("slow");  
popupStatus = 0;  
}  
} 


function edit()
{
	closePopup('profilePopup');
	openPopup('editProfilePopup');
}


function save()
{
	var username= $("#editusername").val();
	var firstname = $("#editfirstname").val();
	var lastname = $("#editlastname").val();
	var email = $("#editemail").val();

	var data="save=&firstname="+firstname+"&lastname="+lastname+"&email="+email;

	$.ajax({
	url: "project_leader_page.php",
	type: "POST",
	data: data,
	success: function(html)
		{
		closePopup('editProfilePopup');	
		showMessage("Profile edited");
		$("#profilePopup").html(html);
		}
	});
}

function showMessage(msg)
{
	$("#msg").html(msg).css("visibility","visible").animate({opacity:0},5500,function() 
	{

		$("#msg").css("visibility","hidden").css("opacity",1);	
	});
}

function changePassword()
{
	closePopup('editProfilePopup');
	openPopup('changePasswordPopup');
}

function change()
{
	old=$("#oldpass").val();
	newp=$("#newpass").val();
	cnewp=$("#cnewpass").val();
	if(old==newp)
	{	
		alert("Please enter different password");
		$("#oldpass").val("");
		$("#newpass").val("");
		$("#cnewpass").val("");
		return false;
	}
	if(newp==cnewp)
	{
		
		var data="change=&old="+old+"&newp="+newp;
		$.ajax
		({
			url: "project_leader_page.php",
			type: "POST",
			data:data,
			success: function(html)
			{
				if(html==1)
				{
					$("#oldpass").val("");
					$("#newpass").val("");
					$("#cnewpass").val("");
					closePopup('changePasswordPopup');
					showMessage("Password Changed");

				}
				else
					alert("Invalid password");
					$("#oldpass").val("");
					$("#newpass").val("");
					$("#cnewpass").val("");
			}
		});
	}   
	else
	{
		alert("Password not matching");
		$("#oldpass").val("");
		$("#newpass").val("");
		$("#cnewpass").val("");
	}
}

function ds(el)
{
	$('#'+el.id).next('#det:hidden').css('display','table-row').siblings('#det:visible').css('display','none');
}